package rabbitmq.topic;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import rabbitmq.utils.MqUtil;

import java.io.IOException;

public class Consumer01 {

    private final static String TOPIC_MSG="TOPIC_MSG";

    public static void main(String[] args) throws IOException {
        MqUtil mqUtil=new MqUtil();
        Channel channel = mqUtil.getChananel();
        channel.exchangeDeclare(TOPIC_MSG,BuiltinExchangeType.TOPIC);
        String queueName="Q1";
        channel.queueDeclare(queueName,false,false,false,null);
        channel.queueBind(queueName,TOPIC_MSG,"*.orange.*");

        DeliverCallback deliverCallback = (consumeTag,delivery)->{
            String msg=new String(delivery.getBody(),"UTF-8");
            System.out.println("消费者01消费了："+msg);
        };
        channel.basicConsume(queueName,true,deliverCallback,consumerTag->{});

    }
}
